﻿using System.Linq;
using System.Web;
using Bricks.Caching;

namespace Motar.Web.Caching
{

    /// <summary>
    /// 
    /// </summary>
    public class HttpApplicationCacheFacade : CacheFacadeBase<HttpApplicationState>, IHttpApplicationCacheFacade
    {

        /// <summary>
        /// 
        /// </summary>
        public HttpApplicationCacheFacade() :
            base(() => HttpContext.Current.Application)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public override void Add(string key, object value)
        {
            Execute(application => application.Add(key, value));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public override bool Contains(string key)
        {
            return Execute<bool>(application => application.AllKeys.Contains(key));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public override object Get(string key)
        {
            return Execute<object>(application => application[key]);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        public override void Remove(string key)
        {
            Execute(application => application.Remove(key));
        }

        /// <summary>
        /// 
        /// </summary>
        public override void Flush()
        {
            Execute(application => application.Clear());
        }
    }
}
